<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Config extends Model
{


    public function get_banner()
    {
        $datas = $this->where('name','like','APP_BANNER_IMG%')->get(['value','sort']);
        $datas->each(function($data){
            $data->value = config('app.url').'/uploads/'.$data->value;
        });
        return $datas;
    }

    public function kefu_config()
    {
        $kefu_tel = $this->where('name', 'KEFU_TEL')->value('value');
        $kefu_wechat = $this->where('name', 'KEFU_WECHAT')->value('value');
        $data['kefu_tel'] = isset($kefu_tel)?$kefu_tel : "";
        $data['kefu_wechat'] = config('app.img_url').$kefu_wechat;

        return $data;
    }

    public function about_us_config()
    {
        $about_us_data = [];
        $app_logo_addr = $this->where('name', 'APP_ABOUTUS_LOGO')->value('value');
        $app_name = $this->where('name', 'APP_NAME')->value('value');
        $app_version = $this->where('name', 'APP_VERSION')->value('value');
        $company_name = $this->where('name', 'COMPANY_NAME')->value('value');
        $company_tel = $this->where('name', 'COMPANY_PHONE')->value('value');

        $about_us_data['app_logo_addr'] = isset($app_logo_addr) ? config('app.url') . '/uploads/' . $app_logo_addr : "";
        $about_us_data['app_name'] = isset($app_name) ? $app_name : "";

        $about_us_data['app_version'] = isset($app_version) ? $app_version : "";

        $about_us_data['company_name'] = isset($company_name) ? $company_name : "";

        $about_us_data['company_tel'] = isset($company_tel)?$company_tel:"";
        

        return $about_us_data;
    }

    public function getEClotheBanner()
    {
        $datas=$this->where('name','like','E_CLOTHE_BANNER%')->get(['value','sort']);

        $datas->each(function($data){
            $data->value = config('app.img_url').$data->value;
        });
        return $datas->pluck('value');
    }

    public function get_card_banner()
    {
        $datas=$this->where('name','like','CARD_BANNER%')->get(['value','sort']);

        $datas->each(function($data){
            $data->value = config('app.img_url').$data->value;
        });
        return $datas->pluck('value');
    }

    public function getEClothePlatform()
    {
        $datas=$this->where('name','E_CLOTHE_PLATFORM')->get(['value']);

        $datas->each(function($data){
            $data->value = config('app.url').'/uploads/'.$data->value;
        });

        if(!empty($datas)){

            $datas=$datas[0]->value;
        }else{

            $datas='';
        }

        return $datas;
    }


    public function tradeConfig()
    {
        $data = [];

        $exchange_rate = $this->where('name', 'EXCHANGE_RATE')->value('value');

        $data['exchange_rate'] = $exchange_rate;
        
        return $data;
    }


}
